// Package sys
// @Link  https://github.com/bufanyun/hotgo
// @Copyright  Copyright (c) 2025 HotGo CLI
// @Author  Ms <133814250@qq.com>
// @License  https://github.com/bufanyun/hotgo/blob/master/LICENSE
// @AutoGenerate Version 2.15.11
package sys

import (
	"context"
	"hotgo/api/admin/product"
	"hotgo/internal/model/input/sysin"
	"hotgo/internal/service"
)

var (
	Product = cProduct{}
)

type cProduct struct{}

// List 查看商品中心列表
func (c *cProduct) List(ctx context.Context, req *product.ListReq) (res *product.ListRes, err error) {

	list, totalCount, err := service.SysProduct().List(ctx, &req.ProductListInp)
	if err != nil {
		return
	}

	if list == nil {
		list = []*sysin.ProductListModel{}
	}

	res = new(product.ListRes)
	res.List = list
	res.PageRes.Pack(req, totalCount)
	return
}

// Edit 更新商品中心
func (c *cProduct) Edit(ctx context.Context, req *product.EditReq) (res *product.EditRes, err error) {
	err = service.SysProduct().Edit(ctx, &req.ProductEditInp)
	return
}

// View 获取指定商品中心信息
func (c *cProduct) View(ctx context.Context, req *product.ViewReq) (res *product.ViewRes, err error) {
	data, err := service.SysProduct().View(ctx, &req.ProductViewInp)
	if err != nil {
		return
	}

	res = new(product.ViewRes)
	res.ProductViewModel = data
	return
}

// Status 更新商品中心状态
func (c *cProduct) Status(ctx context.Context, req *product.StatusReq) (res *product.StatusRes, err error) {
	err = service.SysProduct().Status(ctx, &req.ProductStatusInp)
	return
}
